package cn.wolfcode.shop.cloud.common;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class Result<T> {
    private String msg;
    private int code;
    private T data;

    public static final int SUCCESS_CODE = 200;
    public static final String SUCCESS_MSG = "操作成功";
    public static final int DEFAULT_ERROR_COED = 50001;
    public static final String DEFAULT_ERROR_MSG = "服务器繁忙";

    public Result success() {
        return new Result(Result.SUCCESS_MSG, Result.SUCCESS_CODE, null);
    }

    public Result success(T data) {
        return new Result(Result.SUCCESS_MSG, Result.SUCCESS_CODE, data);
    }

    public Result success(String msg, T data) {
        return new Result(msg, Result.SUCCESS_CODE, data);
    }

    public Result error(CodeMsg codeMsg) {
        return new Result(codeMsg.getMsg(), codeMsg.getCode(), null);
    }

    public Result defaultError() {
        return new Result(Result.DEFAULT_ERROR_MSG, Result.DEFAULT_ERROR_COED, null);
    }

}
